package com.jjkj.environmental.environmental.adapter

import android.graphics.Color
import android.support.annotation.LayoutRes
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.jjkj.environmental.environmental.R
import com.jjkj.environmental.environmental.bean.model.CheckItem
import java.io.File

class CheckAdapter(@LayoutRes layoutResId: Int) : BaseQuickAdapter<CheckItem, BaseViewHolder>(layoutResId) {


    override fun convert(helper: BaseViewHolder?, item: CheckItem?) {
        helper!!.setText(R.id.tv_picture_name, item!!.name)
        helper.addOnClickListener(R.id.img_picture_delete)
        if (item.status == 0) {
            helper.getView<View>(R.id.img_picture_delete).visibility = View.GONE
        } else {
            helper.getView<View>(R.id.img_picture_delete).visibility = View.VISIBLE
        }
        val imageView = helper.getView<ImageView>(R.id.img_picture)
        val textView = helper.getView<TextView>(R.id.tv_picture_status)
        val options = RequestOptions()
                .error(R.mipmap.empty_picture)
        Glide.with(imageView).load(File(item.path)).apply(options).into(imageView)
        when (item.status) {
            0 -> {
                textView.text = "未拍照"
                textView.setTextColor(Color.RED)
                textView.setBackgroundResource(R.drawable.un_select)
            }
            1 -> {
                textView.setTextColor(Color.parseColor("#FFFF8800"))
                textView.setBackgroundResource(R.drawable.un_upload)
                textView.text = "上传中..."
            }
            2 -> {
                textView.setTextColor(Color.GREEN)
                textView.setBackgroundResource(R.drawable.upload_success)
                textView.text = "上传成功"
            }
            3 -> {
                textView.setTextColor(Color.parseColor("#FFFF8800"))
                textView.setBackgroundResource(R.drawable.un_upload)
                textView.text = "上传失败"
            }
        }
    }
}